﻿using System;
using System.Collections.Generic;
using System.Text;
using WeatherSystem.Application.ContentAdapter.EventAdapter;
using WeatherSystem.Application.MsgHandler;
using WeatherSystem.Data.Response;

namespace WeatherSystem.Application.ContentAdapter.Base
{
    class EventManager : AdapterBase, Adapter
    {
        public override Type AdaptType => typeof(EventMessage);
        private static List<Adapter> EventAdapters = new List<Adapter>();
        private static Default DefaultAdapter = new Default();
        public static void AddAdapter(EventAdapterBase adapter)
        {
            foreach (var adpt in EventAdapters)
            {
                var a = adpt as EventAdapterBase;
                if (a.EventName == adapter.EventName) return;
            }
            EventAdapters.Add(adapter);
        }
        public ResponseMessageBase Handle(Message message)
        {
            foreach (var adapter in EventAdapters)
            {
                var adapter_base = adapter as EventAdapterBase;
                if (adapter_base.Adapt(message as EventMessage))
                {
                    return adapter.Handle(message);
                }
            }
            return DefaultAdapter.Handle(message);
        }
    }

}
